/*   1:    */ package com.atomikos.swing;
/*   2:    */ 
/*   3:    */ import java.awt.BorderLayout;
/*   4:    */ import java.awt.Dimension;
/*   5:    */ import java.awt.FlowLayout;
/*   6:    */ import java.awt.event.ActionEvent;
/*   7:    */ import java.awt.event.ActionListener;
/*   8:    */ import java.util.Enumeration;
/*   9:    */ import java.util.ResourceBundle;
/*  10:    */ import java.util.Vector;
/*  11:    */ import javax.swing.JButton;
/*  12:    */ import javax.swing.JPanel;
/*  13:    */ import javax.swing.JScrollPane;
/*  14:    */ import javax.swing.JTable;
/*  15:    */ import javax.swing.ListSelectionModel;
/*  16:    */ import javax.swing.event.ListSelectionEvent;
/*  17:    */ import javax.swing.event.ListSelectionListener;
/*  18:    */ 
/*  19:    */ public class PropertiesPanel
/*  20:    */   implements ActionListener
/*  21:    */ {
/*  22:    */   private static final int NONE_SELECTED = -1;
/*  23:    */   private JPanel panel_;
/*  24:    */   private JButton newButton_;
/*  25:    */   private JButton deleteButton_;
/*  26:    */   private JButton editButton_;
/*  27:    */   private PropertiesTableModel model_;
/*  28:    */   private Vector listeners_;
/*  29:    */   private int currentRow_;
/*  30:    */   
/*  31:    */   public PropertiesPanel(PropertiesTableModel model)
/*  32:    */   {
/*  33: 82 */     this(model, false);
/*  34:    */   }
/*  35:    */   
/*  36:    */   public PropertiesPanel(PropertiesTableModel model, boolean readonly)
/*  37:    */   {
/*  38: 98 */     this.panel_ = new JPanel();
/*  39: 99 */     ResourceBundle messages = ResourceBundle.getBundle("com.atomikos.swing.PropertiesPanelResourceBundle");
/*  40:    */     
/*  41:    */ 
/*  42:102 */     this.panel_.setLayout(new BorderLayout());
/*  43:103 */     JTable table = new JTable(model.getTableModel());
/*  44:104 */     Dimension dim = new Dimension(200, 90);
/*  45:105 */     table.setPreferredScrollableViewportSize(dim);
/*  46:106 */     JScrollPane scroller = new JScrollPane(table);
/*  47:107 */     this.panel_.add(scroller, "Center");
/*  48:108 */     this.model_ = model;
/*  49:109 */     JPanel buttons = new JPanel();
/*  50:110 */     buttons.setLayout(new FlowLayout());
/*  51:111 */     this.newButton_ = new JButton(messages.getString("newButtonName"));
/*  52:112 */     this.newButton_.addActionListener(this);
/*  53:113 */     this.deleteButton_ = new JButton(messages.getString("deleteButtonName"));
/*  54:114 */     this.deleteButton_.setEnabled(false);
/*  55:115 */     this.deleteButton_.addActionListener(this);
/*  56:116 */     if (!readonly)
/*  57:    */     {
/*  58:117 */       buttons.add(this.newButton_);
/*  59:118 */       buttons.add(this.deleteButton_);
/*  60:119 */       this.editButton_ = new JButton(messages.getString("editButtonName"));
/*  61:    */     }
/*  62:    */     else
/*  63:    */     {
/*  64:122 */       this.editButton_ = new JButton(messages.getString("viewButtonName"));
/*  65:    */     }
/*  66:124 */     this.editButton_.setEnabled(false);
/*  67:125 */     this.editButton_.addActionListener(this);
/*  68:126 */     buttons.add(this.editButton_);
/*  69:127 */     this.panel_.add(buttons, "South");
/*  70:    */     
/*  71:129 */     this.listeners_ = new Vector();
/*  72:130 */     this.currentRow_ = -1;
/*  73:    */     
/*  74:    */ 
/*  75:133 */     table.setSelectionMode(0);
/*  76:134 */     ListSelectionModel rowSM = table.getSelectionModel();
/*  77:    */     
/*  78:136 */     rowSM.addListSelectionListener(new ListSelectionListener()
/*  79:    */     {
/*  80:    */       public void valueChanged(ListSelectionEvent e)
/*  81:    */       {
/*  82:139 */         if (e.getValueIsAdjusting()) {
/*  83:140 */           return;
/*  84:    */         }
/*  85:142 */         ListSelectionModel lsm = (ListSelectionModel)e.getSource();
/*  86:144 */         if (lsm.isSelectionEmpty())
/*  87:    */         {
/*  88:146 */           PropertiesPanel.this.currentRow_ = -1;
/*  89:147 */           PropertiesPanel.this.editButton_.setEnabled(false);
/*  90:148 */           PropertiesPanel.this.deleteButton_.setEnabled(false);
/*  91:    */         }
/*  92:    */         else
/*  93:    */         {
/*  94:150 */           PropertiesPanel.this.currentRow_ = lsm.getMinSelectionIndex();
/*  95:151 */           PropertiesPanel.this.editButton_.setEnabled(true);
/*  96:152 */           PropertiesPanel.this.deleteButton_.setEnabled(true);
/*  97:    */         }
/*  98:    */       }
/*  99:    */     });
/* 100:    */   }
/* 101:    */   
/* 102:    */   public synchronized void actionPerformed(ActionEvent e)
/* 103:    */   {
/* 104:165 */     int i = -1;
/* 105:166 */     if (e.getSource() == this.newButton_) {
/* 106:167 */       i = 0;
/* 107:168 */     } else if (e.getSource() == this.editButton_) {
/* 108:169 */       i = 1;
/* 109:170 */     } else if (e.getSource() == this.deleteButton_) {
/* 110:171 */       i = 2;
/* 111:    */     }
/* 112:173 */     Enumeration enumm = this.listeners_.elements();
/* 113:174 */     while (enumm.hasMoreElements())
/* 114:    */     {
/* 115:175 */       PropertyListener l = (PropertyListener)enumm.nextElement();
/* 116:176 */       switch (i)
/* 117:    */       {
/* 118:    */       case 0: 
/* 119:177 */         l.newProperty(this.model_);
/* 120:178 */         break;
/* 121:    */       case 1: 
/* 122:179 */         l.editProperty(this.model_, this.currentRow_);
/* 123:180 */         break;
/* 124:    */       case 2: 
/* 125:181 */         l.deleteProperty(this.model_, this.currentRow_);
/* 126:182 */         this.deleteButton_.setEnabled(false);
/* 127:183 */         this.editButton_.setEnabled(false);
/* 128:    */       }
/* 129:    */     }
/* 130:    */   }
/* 131:    */   
/* 132:    */   public synchronized void addPropertyListener(PropertyListener l)
/* 133:    */   {
/* 134:198 */     this.listeners_.addElement(l);
/* 135:    */   }
/* 136:    */   
/* 137:    */   public synchronized void removePropertyListener(PropertyListener l)
/* 138:    */   {
/* 139:208 */     this.listeners_.remove(l);
/* 140:    */   }
/* 141:    */   
/* 142:    */   public JPanel getPanel()
/* 143:    */   {
/* 144:218 */     return this.panel_;
/* 145:    */   }
/* 146:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.swing.PropertiesPanel
 * JD-Core Version:    0.7.0.1
 */